﻿using Unity.VisualScripting;
using UnityEngine;

namespace UniFramework.Actor
{
	/// <summary>
	/// 渲染对象
	/// </summary>
	public abstract class RenderObject : MonoBehaviour
	{
		protected LogicObject logicObject;
		public float moveSpeed = 10f;
		public bool isInit = false;


		public abstract void OnCreate();

		public abstract void OnRelease();

		protected virtual void Update()
		{
			if (!isInit) return;
			UpdatePosition();
		}

		public virtual void OnDestroy()
		{
		}


		public void SetLogicObjectAndInitData(LogicObject logicObject)
		{
			this.logicObject = logicObject;
			transform.position = logicObject.LogicPos.ToVector3();
		}

		protected virtual void UpdatePosition()
		{
			if (this.IsDestroyed()) return;
			transform.position = Vector3.Lerp(transform.position, logicObject.LogicPos.ToVector3(),
				moveSpeed * Time.deltaTime);
		}
	}
}